<template>
	<!-- 井控智算软件 -->
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="液体密度 ρ (g/cm³)" prop="mudDensity">
				<u-input :border="border" placeholder="请输入液体密度" v-model="model.mudDensity" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="液柱高度 H (m)" prop="wellDepth">
				<u-input :border="border" placeholder="请输入液柱高度" v-model="model.wellDepth" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="静液压力的值为：" prop="formationPressure">
					<span v-if="model.formationPressure"> {{model.formationPressure}} MPa </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">静液压力=（10^-3ρgH）=0.0098ρH</view>
				<view class="u-item-desc">式中：</view>
				<view class="u-item-desc">g—重力9.81N/Kg；</view>
				<view class="u-item-desc">ρ—液体密度，g/cm3；</view>
				<view class="u-item-desc">H—液柱的垂直高度，m。</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					mudDensity: '',
					wellDepth: '',
					formationPressure: ''
				},
				rules: {
					mudDensity: [{
						required: true,
						message: '请输入液体密度',
						trigger: 'blur'
					}],
					wellDepth: [{
						required: true,
						message: '请输入液柱高度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const ρ = parseFloat(this.model.mudDensity);
						const H = parseFloat(this.model.wellDepth);
						const g = 9.81; // 重力加速度，m/s²
						
						// Pl = 10⁻³ × ρ × g × H + Pm
						this.model.formationPressure = (0.001 * ρ * g * H).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>